# -*- shell-script -*-

# 41ibm,partition-no - Hardware database scanning routines and variables for
#                      systems with device-tree *and* ibm,parition-no.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2004

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 41ibm,partition-no,v 1.1 2006/04/11 18:38:28 emunson Exp $

# VPD may be partition-local if device-tree has ibm,partition-no property...
if [ -n "$source_device_tree" ] ; then
    [ -f "${source_device_tree}/ibm,partition-no" ] || return 0
elif [ -n "$db_bus_dt_dir" ] ; then
    [ -f "${db_bus_dt_dir}/ibm,partition-no" ] || return 0
else
    return 0
fi

######################################################################

do_fc_hook ()
{
    # Sets: fc

    local dir="$1"

    # By default, VPD is marked global.
    fc='********'

    # VPD is partition-local if device-tree has ibm,partition-no property...
    # ... and is not built-in, or is built-in and has ibm,vpd....
    local bi="${dir}/built-in"
    if [ ! -f "$bi" -o \( -f "$bi" -a -f "${dir}/ibm,vpd" \) ] ; then
	# ... and this or parent PCI node has ibm,my-drc-index property.
	local d="$dir"
	while [ "$fc" = '********' -a \
	    -n "$d" -a "$d" != "/" -a "$d" != "$db_bus_dir" ] ; do
	  local b="${d##*/}" # basename
	  case "$b" in
	      (pci@*) [ -f "${d}/ibm,my-drc-index" ] && \
		  fc='========' ;;
	  esac
	  d="${d%/*}" # dirname
	done
    fi
}
